package Utility
{
	import flexlib.mdi.containers.MDICanvas;
	import flexlib.mdi.containers.MDIWindow;
	import flexlib.mdi.events.MDIWindowEvent;

	import mx.core.FlexGlobals;
	import mx.core.IVisualElement;

	public class DisplayLoader
	{
		public var displayObj:MDIWindow=new MDIWindow();

		public function DisplayLoader()
		{
		}
		
		//清理已打开的窗口
		public function clear(obj:MDIWindow):void
		{
			if (obj != null && obj.parent is MDICanvas)
			{
				FlexGlobals.topLevelApplication.mdic.windowManager.remove(obj);
				obj=null;
			}
		}

		//加载MDI窗口对象
		public function loadObj(obj:MDIWindow):void
		{
			this.displayObj=obj;
			FlexGlobals.topLevelApplication.mdic.windowManager.add(obj);
			obj.addEventListener(MDIWindowEvent.CLOSE, closeObj);
			obj.x=0;
			obj.y=0;
		}



		//在用户关闭窗口后从MDI容器中移除窗口对象，并且将显示对象置空。
		public function closeObj(e:MDIWindowEvent):void
		{
			FlexGlobals.topLevelApplication.mdic.windowManager.remove(displayObj);
			this.displayObj=null;
		}
		
		/**
		 * 关闭当前窗口
		 **/
		public function closeMDIWindow(mdiWindow:MDIWindow):void
		{
			if(mdiWindow.windowManager!=null && mdiWindow!=null)
			{
				FlexGlobals.topLevelApplication.mdic.windowManager.remove(mdiWindow);
				mdiWindow=null;
				//FlexGlobals.topLevelApplication.markLayer.removeAllChildren();
			}
		}
		/**
		 * 关闭所有窗口
		 * */
		public function closeAllMDIWindow():void
		{
			FlexGlobals.topLevelApplication.mdic.removeAllElements();
		
		}
	}
}